import {
    Entity,
    PrimaryKey,
    Property,
    ManyToOne,
    Reference,
} from "@mikro-orm/core";
import { BaseEntity } from "./Base";
import { User } from "./User";

@Entity()
export class App extends BaseEntity {
    @Property({ type: "string" })
    name: string;

    @Property({ type: "string" })
    introduce: string;

    @Property({ type: "string" })
    type: string; // frontend, backend, fullstack

    @Property({ type: "string", hidden: true })
    secret!: string; // app secret for get its configs

    @ManyToOne({ entity: () => User, nullable: true })
    admin!: Reference<User>; // response to filed 'admin_id'

    @Property({ type: "numeric", columnType: "int", default: 0 })
    isDelete: number = 0;

    constructor({
        name,
        type = "frontend",
        introduce = "",
        user,
        secret,
    }: {
        name: string;
        type: string;
        introduce: string;
        user: Reference<User>;
        secret: string;
    }) {
        super();
        this.name = name;
        this.introduce = introduce;
        this.type = type;
        this.admin = user;
        this.secret = secret;
    }
}
